package sf.actions;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.HashMap;

import javax.swing.JTable;

import sf.view.StandardForm;
import sf.view.fields.ZoomField;

public class ActionZoomOut extends SFAbstractAction {

	private static final long serialVersionUID = 2649560088378073465L;
	private StandardForm parentForm;
	private HashMap<String, Object> storedRow;

	public ActionZoomOut(StandardForm parentForm) {
		this.parentForm = parentForm;
		putValue(MNEMONIC_KEY, KeyEvent.VK_V); // TODO precica
		putValue(SMALL_ICON, loadIcon("img/zoom_out.png"));
		putValue(NAME, "Zoom Out");
		putValue(SHORT_DESCRIPTION, "Zoom Out");
	}

	public HashMap<String, Object> getStoredRow() {
		return storedRow;
	}

	public void actionPerformed(ActionEvent e) {
		JTable tempTable = parentForm.getBrowser().getTable();
		int selectedRow = tempTable.getSelectedRow();
		storedRow = new HashMap<String, Object>();
		for (int i = 0; i < tempTable.getModel().getColumnCount(); i++) {
			storedRow.put(tempTable.getModel().getColumnName(i), tempTable
					.getModel().getValueAt(selectedRow, i));
		}

		((ZoomField) (parentForm.getContext().getCaller())).setValue(storedRow);
		//TODO: close this form
	}
}
